namespace Day23Movies.Data.Migrations
{
    using Day23Movies.Data.Models;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<Day23Movies.Data.MoviesContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(Day23Movies.Data.MoviesContext context)
        {
            UserStore<User> store = new UserStore<User>(context);
            UserManager<User> manager = new UserManager<User>(store);

            User nick = manager.FindByName("nick");

            if (nick == null)
            {
                manager.Create(new User
                {
                    UserName = "Nick"
                });

                nick = manager.FindByName("Nick");
            }

            context.Movies.AddOrUpdate(m => m.Title,
                new Movie() { Title = "Star Wars", Rating = 5, UserId = nick.Id, PosterUrl = "http://votemenot.com/upload/768/7684.jpg" },
                new Movie() { Title = "Tombstone", Rating = 5, UserId = nick.Id, PosterUrl = "https://www.movieposter.com/posters/archive/main/15/A70-7548" },
                new Movie() { Title = "X-Men: The Last Stand", Rating = 2, UserId = nick.Id, PosterUrl = "https://www.movieposter.com/posters/archive/main/68/MPW-34042" }
            );
        }
    }
}
